<template>
  <div ref="body">
    <Row style="padding: 8px">
                <span style="float: left;">
                 <Button type="primary" style="" @click="handleAdd">新增保障人员收入</Button>
                     </span>
<!--      <span style="float: left;margin-left: 3px">-->
<!--                 <Button type="primary" style="" @click="handleAdd2">新增非保障人员收入</Button>-->
<!--                     </span>-->
    </Row>
    <div style="margin-top:10px ">
      <vxe-table border
                 auto-resize
                 row-id="id"
                 :row-key="true"
                 show-overflow="tooltip"
                 highlight-hover-row
                 align="center"
                 header-align="center"
                 ref="xTree"
                 :loading="Loading"
                 :data="tableData">
        <vxe-table-column field="azcp0003" title="收入所属 " align="center" min-width="100"/>
        <vxe-table-column field="ssba0010_name" title="收入类型" align="center" min-width="200"/>
        <vxe-table-column field="ssba0011_name" title="收入详细分类" align="center" min-width="200"/>
        <vxe-table-column field="ssba0012_name" title="收入计算方式" align="center" min-width="200"/>
        <vxe-table-column field="ssba0006" title="月收入金额" align="center" min-width="100"/>
        <vxe-table-column title="操作" align="center" fixed="right" min-width="200">
          <template #default="{row}">
            <Button type="info" size="small" @click="handleEdit(row)" v-if="row.user_type=='1'">编辑</Button>
            <Button type="info" size="small" @click="handleEdit2(row)" v-else>编辑</Button>
            <Button type="error" size="small" @click="handleDelete(row.id)" style="margin-left: 5px"  v-if="row.user_type=='1'">删除 </Button>
            <Button type="error" size="small" @click="handleDelete2(row.id)" style="margin-left: 5px" v-else>删除 </Button>
            <Button type="success" size="small" @click="handleDetail(row)" style="margin-left:5px" v-if="row.user_type=='1'">  详情 </Button>
            <Button type="success" size="small" @click="handleDetail2(row)" style="margin-left:5px" v-else>详情 </Button>
          </template>
        </vxe-table-column>
      </vxe-table>
      <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
            @on-change="handleTableChange" :current="pageNo"></Page>
    </div>

    <ss11003-modal ref="modalForm" @ok="modalFormOk"/>
    <ss11014-modal ref="modalForm2" @ok="modalFormOk"/>
    <div style="height:40px;line-height:40px;margin-top:10px;text-align: center ">
      <Button @click="prevStep">上一步</Button>
      <Button type="primary" @click="nextStep" style="margin-left:20px" :loading="btnLoading">下一步
      </Button>
    </div>
  </div>
</template>

<script>
import {CommonMixin} from '@/views/common/js/CommonMixin'
import Ss11003Modal from './modules/Ss11003Modal'
import Ss11014Modal from './modules/Ss11014Modal'
import {getAction, postAction} from '@/api/request'

export default {
  name: "application3",
  mixins: [CommonMixin],
  components: {Ss11003Modal, Ss11014Modal},
  data() {
    return {
      url: {
        list: "/api/ac/subsistence/ss11003Service/getPageList",
        delete: "/api/ac/subsistence/ss11003Service/deleteData",
        check: "/api/ac/subsistence/ss11003Service/creatCheck",
        delete2: "/api/ac/subsistence/ss11003Service/deleteData",
      },
      Loading: true,
      queryParam: {
        azcp0500: this.$parent.familyInfo.ss11001Id,
        azdf0007: this.$parent.familyInfo.azdf0007,
      },
      btnLoading: false,
    }
  },
  methods: {
    handleEdit2: function (row) {
      this.$refs.modalForm2.title = "编辑";
      this.$refs.modalForm2.disableSubmit = false;
      this.$refs.modalForm2.key = this.uuid();
      this.$refs.modalForm2.edit(row);
    },
    handleAdd2: function () {
      this.$refs.modalForm2.title = "新增";
      this.$refs.modalForm2.disableSubmit = false;
      this.$refs.modalForm2.key = this.uuid();
      this.$refs.modalForm2.add();
    },
    handleDetail2: function (row) {
      this.$refs.modalForm2.title = "详情";
      this.$refs.modalForm2.disableSubmit = true;
      this.$refs.modalForm2.key = this.uuid();
      this.$refs.modalForm2.edit(row);
    },
    handleDelete2: function (id) {
      this.$Modal.confirm({
        title: '确定删除吗？',
        onOk: () => {
          if (!this.url.delete) {
            this.$Message.error("请设置url.delete属性!")
            return
          }
          var that = this;
          postAction(that.url.delete2, {id: id}).then((res) => {
            if (res.data.errcode == 0) {
              //重新计算分页问题
              that.reCalculatePage(1);
              that.$Message.success("删除成功！");
            } else {
              that.$Message.error(res.data.errmsg);
            }
          });
        }
      })
    },
    prevStep() {
      this.$emit('prevStep');
    },
    nextStep() {
      var url = this.url.check;
      this.btnLoading = true;
      var that = this;
      postAction(url, {azcp0500: this.$parent.familyInfo.ss11001Id}).then((res) => {
        if (res.data.errcode == 0) {
          this.$emit('nextStep')
        } else {
          if (res.data.errmsg.indexOf("重新计算") != -1) {
            this.$Modal.error({
              title: '提示',
              content: res.data.errmsg,
              onOk: this.loadData()
            });
          } else {
            that.$Message.error(res.data.errmsg);
          }
        }
      }).finally(() => {
        that.btnLoading = false;
      });
    },
  },
  created() {
    this.loadData();
  },
}
</script>

<style scoped>

</style>
